package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.CategoryBrandMapper;
import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.product.CategoryBrandVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {
    @Resource
    CategoryBrandMapper categoryBrandMapper;
    @Override
    public PageInfo<CategoryBrandVo> page(Integer pageNum, Integer pageSize, CategoryBrandDto categoryBrandDto) {
        PageHelper.startPage(pageNum,pageSize , true,true,null);
        //多表联查 分页数据
        return new PageInfo<CategoryBrandVo>(categoryBrandMapper.selectPage(categoryBrandDto));
    }

    @Override
    public void deleteById(Long id) {
        categoryBrandMapper.deleteById(id);
    }

    @Override
    public void save(CategoryBrand categoryBrand) {
        categoryBrand.setCreateTime(new Date());
        categoryBrand.setUpdateTime(new Date());
        categoryBrandMapper.save(categoryBrand);
    }

    @Override
    public void updateById(CategoryBrand categoryBrand) {
        categoryBrand.setUpdateTime(new Date());
        categoryBrandMapper.updateById(categoryBrand);
    }

    @Override
    public List<Brand> listBrandsByCategoryId(Long categoryId) {

        return categoryBrandMapper.selectBrandsByCategoryId(categoryId);
    }
}
